﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
/*
namespace Flame.Reflection
{
    class IntellisenseForType
    {
        static IntellisenseParsing _methodAutocompleteParsing, _memberAutocompleteParsing;
        public IntellisenseForType()
        {
            //_allnamespaceAndType = new AllNamespaceAndType();
            _methodAutocompleteParsing = new IntellisenseParsing(IntellisenseParsing.RegexStringBuilder(@"", @"(\$)?[a-zA-Z0-9_\:\.\[\]\(\)]+", @"((\:\:)|\.)", @"[a-zA-Z0-9_]+", @"\([^\)]*"));
            //_memberAutocompleteParsing = new IntellisenseParsing(IntellisenseParsing.RegexStringBuilder(@"", @"(\$)?[a-zA-Z0-9_\:\.\[\]\(\)]+", @"((\:\:)|\.)?", @"[a-zA-Z0-9_]*", @""));
            _memberAutocompleteParsing = new IntellisenseParsing(IntellisenseParsing.RegexStringBuilder(@"", @"(\$)?[a-zA-Z0-9_\:\.\[\]\(\)]+", @"((\:\:)|\.)", @"[a-zA-Z0-9_]*", @""));
        }

        int startingWithCount = 0;

        bool parsing(string name, string spartialvalue)
        {
            string nameLower = name.ToLower();
            string spartialvalueLower = spartialvalue.ToLower();
            if (nameLower.StartsWith(spartialvalueLower))
            {
                startingWithCount++;
                return true;
            }
            return nameLower.Contains(spartialvalue.ToLower());
        }

        bool methodcondition(MethodInfo m, string spartialvalue, bool all)
        {
            return (m.IsPublic || all) && !m.IsSpecialName && parsing(m.Name, spartialvalue);
        }

        bool fieldcondition(FieldInfo m, string spartialvalue, bool all)
        {
            return (m.IsPublic || all) && !m.IsSpecialName && parsing(m.Name, spartialvalue);
        }

        IEnumerable<string> types(Type t, string spartialvalue)
        {
            return (from m in t.GetNestedTypes() where parsing(m.Name, spartialvalue) select m.Name + "?3").Distinct<string>();
        }
        IEnumerable<string> methods(Type t, string spartialvalue, bool all)
        {
            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            return (from m in t.GetMethods(flags) where methodcondition(m, spartialvalue, all) select m.Name + "?0").Distinct<string>();
        }
        IEnumerable<string> events(Type t, string spartialvalue)
        {
            return (from m in t.GetEvents() where parsing(m.Name, spartialvalue) select m.Name + "?1").Distinct<string>();
        }
        IEnumerable<string> properties(Type t, string spartialvalue)
        {
            return (from m in t.GetProperties() where parsing(m.Name, spartialvalue) select m.Name + "?2").Distinct<string>();
        }

        IEnumerable<FieldInfo> getAllFields(Type t)
        {
            if (t == null)
                return Enumerable.Empty<FieldInfo>();

            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            return t.GetFields(flags).Union(getAllFields(t.BaseType));
        }
        IEnumerable<string> fields(Type t, string spartialvalue, bool all)
        {
            return (from m in getAllFields(t) where fieldcondition(m, spartialvalue, all) select m.Name + "?3").Distinct<string>();
        }

        public Flame.Reflection.IntellisenseHelper.Result GetListOfMembers(string text, IIntellisense compiler, bool publiconly = true)
        {
            startingWithCount = 0;
            List<string> listOfNames = null;
            string spartialvalue = "";
            Type t = _memberAutocompleteParsing.GetType(text, compiler, out spartialvalue);
            //uu// "RubyModule"??
            if (t != null && t.Name != "RubyModule")
            {
                listOfNames = methods(t, spartialvalue, !publiconly).ToList<string>();
                listOfNames = listOfNames.Concat<string>(fields(t, spartialvalue, !publiconly)).ToList<string>();
                listOfNames = listOfNames.Concat<string>(events(t, spartialvalue)).ToList<string>();
                listOfNames = listOfNames.Concat<string>(properties(t, spartialvalue)).ToList<string>();
                listOfNames = listOfNames.Concat<string>(types(t, spartialvalue)).ToList<string>();
            }
            if (listOfNames == null) return null;
            return new Flame.Reflection.IntellisenseHelper.Result() { List = listOfNames, PartialLength = spartialvalue.Length, StartingWithCount = startingWithCount };
        }

        public Flame.Reflection.IntellisenseHelper.Result GetListOfNames(string text)
        {
            startingWithCount = 0;
            List<string> listOfNames = null;
            string svalue, spartialvalue = "";
            _memberAutocompleteParsing.getMatchResults(text, out svalue, out spartialvalue);

            string[] names = svalue.Split(':', '.');
            var namesNotEmpty = from s in names where s != "" select s;

            List<Class> list = _allnamespaceAndType.AvailableNames(namesNotEmpty);
            if (list != null)
                listOfNames = (from s in (from c in list select namespaceOrClass(c, spartialvalue)) where s != null select s).ToList<string>();

            if (listOfNames == null) return null;
            return new Flame.Reflection.IntellisenseHelper.Result() { List = listOfNames, PartialLength = spartialvalue.Length, StartingWithCount = startingWithCount };
        }
    }
}*/
